package com.pet.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;

import org.apache.struts2.views.jsp.StrutsBodyTagSupport;
import com.pet.framework.util.StringUtil;
import com.pet.server.po.SysUser;
import com.pet.system.util.SessionHelper;

public class RoleLevelTag extends StrutsBodyTagSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String text;
	private Integer level;
	
	

	@Override
	public int doEndTag() throws JspException {
		try {
			BodyContent content = getBodyContent();
			if(!StringUtil.isEmpty(content)){
				setText(content.getString());
			}
			pageContext.getOut().write(gethtml());	
		} catch (IOException e) {
		    e.printStackTrace();	
		}
		return EVAL_PAGE;
	}

	public String gethtml(){
		SysUser user =  SessionHelper.getSysUser();		
		if(user.getRoleInfo().getRoleLevel()!=null && level<=user.getRoleInfo().getRoleLevel()){
			return text;
		}else{
			return "";
		}
		
		
	}
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	@Override
	public int doStartTag() throws JspException {
		return EVAL_BODY_AGAIN;
	}
}
